package com.ruoyi.performance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.performance.domain.TbMatchmakerPerformance;
import com.ruoyi.performance.service.ITbMatchmakerPerformanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.matchmaker.domain.TbMatchmaker;
import com.ruoyi.user.mapper.TbUserMapper;

/**
 * 红娘业绩Controller
 * 
 * @author ruoyi
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/performance/performance")
public class TbMatchmakerPerformanceController extends BaseController
{
    @Autowired
    private ITbMatchmakerPerformanceService tbMatchmakerPerformanceService;

    @Autowired
    private TbUserMapper tbUserMapper;

    /**
     * 查询红娘业绩列表
     */
    @PreAuthorize("@ss.hasPermi('performance:performance:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbMatchmakerPerformance tbMatchmakerPerformance)
    {
        startPage();
        List<TbMatchmakerPerformance> list = tbMatchmakerPerformanceService.selectTbMatchmakerPerformanceList(tbMatchmakerPerformance);
        return getDataTable(list);
    }

    /**
     * 导出红娘业绩列表
     */
    @PreAuthorize("@ss.hasPermi('performance:performance:export')")
    @Log(title = "红娘业绩", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbMatchmakerPerformance tbMatchmakerPerformance)
    {
        List<TbMatchmakerPerformance> list = tbMatchmakerPerformanceService.selectTbMatchmakerPerformanceList(tbMatchmakerPerformance);
        ExcelUtil<TbMatchmakerPerformance> util = new ExcelUtil<TbMatchmakerPerformance>(TbMatchmakerPerformance.class);
        util.exportExcel(response, list, "红娘业绩数据");
    }

    /**
     * 获取红娘业绩详细信息
     */
    @PreAuthorize("@ss.hasPermi('performance:performance:query')")
    @GetMapping(value = "/{performanceId}")
    public AjaxResult getInfo(@PathVariable("performanceId") Long performanceId)
    {
        return success(tbMatchmakerPerformanceService.selectTbMatchmakerPerformanceByPerformanceId(performanceId));
    }

    /**
     * 新增红娘业绩
     */
    @PreAuthorize("@ss.hasPermi('performance:performance:add')")
    @Log(title = "红娘业绩", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbMatchmakerPerformance tbMatchmakerPerformance)
    {
        return toAjax(tbMatchmakerPerformanceService.insertTbMatchmakerPerformance(tbMatchmakerPerformance));
    }

    /**
     * 修改红娘业绩
     */
    @PreAuthorize("@ss.hasPermi('performance:performance:edit')")
    @Log(title = "红娘业绩", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbMatchmakerPerformance tbMatchmakerPerformance)
    {
        return toAjax(tbMatchmakerPerformanceService.updateTbMatchmakerPerformance(tbMatchmakerPerformance));
    }

    /**
     * 删除红娘业绩
     */
    @PreAuthorize("@ss.hasPermi('performance:performance:remove')")
    @Log(title = "红娘业绩", businessType = BusinessType.DELETE)
	@DeleteMapping("/{performanceIds}")
    public AjaxResult remove(@PathVariable Long[] performanceIds)
    {
        return toAjax(tbMatchmakerPerformanceService.deleteTbMatchmakerPerformanceByPerformanceIds(performanceIds));
    }

    /**
     * 根据红娘ID获取红娘详细信息
     */
    @PreAuthorize("@ss.hasPermi('performance:performance:query')")
    @GetMapping("/matchmaker/{matchmakerId}")
    public AjaxResult getMatchmakerInfo(@PathVariable("matchmakerId") Long matchmakerId)
    {
        TbMatchmaker matchmaker = tbUserMapper.selectTbMatchmakerByMatchmakerId(matchmakerId);
        return success(matchmaker);
    }
}
